package ServidorDistribuido;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

public class HiloPorServidorEscritura implements Runnable{
    InetAddress ipCliente = null;
    Socket socketCliente = null;
    private boolean condicionParada = true;

    HiloPorServidorEscritura(InetAddress ipCliente, Socket socketCliente) {
        this.ipCliente = ipCliente;
        this.socketCliente = socketCliente;
    }

    public static void multicastInformacion(String informacion){
        Set <InetAddress> set = Servidor.ipSocket.keySet();
        InetAddress siguienteIp = null;
        Iterator <InetAddress> itr = set.iterator();
        while (itr.hasNext()) {
            Socket socketItr = Servidor.ipSocket.get(itr.next());
            try {
                PrintWriter out = new PrintWriter(new BufferedWriter
                    (new OutputStreamWriter(socketItr.getOutputStream())), true);
                out.println(informacion);
            } catch (IOException ex) {
                Logger.getLogger(HiloPorServidorEscritura.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void run() {
        System.out.println("\nComenzo la ejecucion de HiloPorServidorEscritura.");
        while(Servidor.esCoordinador);
    }
}
